package com.fh.modules.kms.controller;

import com.fh.modules.kms.entity.Knowledge;
import com.fh.modules.kms.service.IElasticService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * @Author qiujunda
 * @Date 20/05/2020
 * @Description 测试用
 */
@Log4j2
//@RestController
//@RequestMapping("/elastic")
public class ElasticController {
    @Autowired
    private IElasticService elasticService;
    @GetMapping("/init")
    @ApiOperation("新增测试")
    public void init(){
        elasticService.createIndex();
        List<Knowledge> list =new ArrayList<>();
        list.add(new Knowledge(1L,"/fhxherp/mgt/saleordersend/getOrderHeaderQHByLine.do","select * from cux_inv_warehouse_area t where t.subinventory_code='2010E021'",1));
        list.add(new Knowledge(2L,"/fhxherp/mgt/saleordersend/addCuxOmShipLinesAll.do ","select * from cux_excel_opt_list  where i_batch=1000081000",2));
//        for(int i=3;i<100;i++){
//            int temp=(int)(Math.random()*100%10);
//            Date date=new Date();
//            date.setMinutes(temp);
//            list.add(new Knowledge(Long.parseLong(String.valueOf(i)),"qiujunda"+temp,"内容啊啊啊 "+i+"啊zxcv",2,date));
//        }
        elasticService.saveAll(list);

    }
    @GetMapping("/all")
    @ApiOperation("查询所有-测试")
    public Iterator<Knowledge> all(){
        return elasticService.findAll();
    }

    @GetMapping("/queryForPage")
    @ApiOperation("分页查询-测试")
    public Page<Knowledge> queryForPage(){
        return elasticService.queryForPage();
    }

    @GetMapping("/queryAggregationForPage")
    @ApiOperation("聚合查询-测试")
    public Object queryAggregationForPage(){
        return elasticService.queryAggregationForPage();
    }
}
